package com.siashan.toolkit.validation.validator;


import com.siashan.toolkit.validation.EnumValue4Int;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


/**
 * 枚举之校验
 *
 * @author siashan
 * @since 2021/7/9 1:41 上午
 */
public class EnumValue4IntValidator implements ConstraintValidator<EnumValue4Int, Object> {

    private int[] intValues;

    @Override
    public boolean isValid(Object o, ConstraintValidatorContext constraintValidatorContext) {
        for (int s : intValues) {
            if (s == ((Integer) o).intValue()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void initialize(EnumValue4Int constraintAnnotation) {
        intValues = constraintAnnotation.intValues();
    }
}
